package classfile

import "math"

/*
CONSTANT_Integer_info {
    u1 tag;
    u4 bytes;
}
java的int 、 short 、 boolean、 byte、 char 存放在这里
*/

type ConstantIntegerInfo struct {
	val int32
}

func (cii *ConstantIntegerInfo) readInfo(reader *ClassReader) {
	bytes := reader.readUint32()
	cii.val = int32(bytes)
}
func (cii *ConstantIntegerInfo) Value() int32 {
	return cii.val
}

/*
CONSTANT_Float_info {
    u1 tag;
    u4 bytes;
}
*/

type ConstantFloatInfo struct {
	val float32
}

func (cfi *ConstantFloatInfo) readInfo(reader *ClassReader) {
	bytes := reader.readUint32()
	cfi.val = math.Float32frombits(bytes)
}

func (cfi *ConstantFloatInfo) Value() float32 {
	return cfi.val
}

/*
CONSTANT_Double_info {
    u1 tag;
    u4 high_bytes;
    u4 low_bytes;
}
*/

type ConstantDoubleInfo struct {
	val float64
}

func (cdi *ConstantDoubleInfo) readInfo(reader *ClassReader) {
	bytes := reader.readUint64()
	cdi.val = math.Float64frombits(bytes)
}
func (cdi *ConstantDoubleInfo) Value() float64 {
	return cdi.val
}

/*
CONSTANT_Long_info {
    u1 tag;
    u4 high_bytes;
    u4 low_bytes;
}
*/

type ConstantLongInfo struct {
	val int64
}

func (cli *ConstantLongInfo) readInfo(reader *ClassReader) {
	bytes := reader.readUint64()
	cli.val = int64(bytes)
}
func (cli *ConstantLongInfo) Value() int64 {
	return cli.val
}
